﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace HexChessBoard
{
    internal static class BoardConstructor
    {
        /// <summary>
        /// Create the tiles in the gameboard for the Glinski/McCooey version, and assign neighbor values.
        /// ^     0
        /// | 3       2
        /// |     T
        /// | 5       4
        /// |     1
        /// ----------->
        /// </summary>
        /// <param name="tiles"></param>
        public static void ConstructTilesGlinskiMcCooey(ref Tile[] tiles)
        {
            //short _dimension = 9;

            //// Initialize the tile array, discovering the proper array size
            //int index = 0;
            //int numTiles = 1;
            //for (int i = _dimension - 1; i > 0; i--)
            //    numTiles += (6 * i);
            //_tiles = new Tile[numTiles];

            //// Tiles are constructed in increasing rank, then file, such as A1, A2, ... A6, B1, B2...
            //// The assumption is that the board is square in this case. C# rounsd integer division to the floor, so add one.
            //for (int i = 0; i < _dimension; i++)
            //{
            //    for (int j = 0; j < _dimension + i; j++)
            //    {
            //        _tiles[index] = new Tile(index, (File)i, (Rank)j);
            //        index++;
            //    }
            //}
            //// Construct the last 5 files (G - L inclusive) with all their ranks (decreasing from 10 max)...
            //for (int i = _dimension; i < (_dimension * 2) - 1; i++)
            //{
            //    for (int j = 0; j < (_dimension * 2) - 1 + (_dimension - 1) - i; j++)
            //    {
            //        _tiles[index] = new Tile(index, (File)i, (Rank)j);
            //        index++;
            //    }
            //}

            //// Construct the neighbors
            //for (index = 0; index < _tiles.Length; index++)
            //{
            //    // Contruct [0] and [1] neighbors
            //    if (index != _tiles.Length - 1 && _tiles[index].file == _tiles[index + 1].file)
            //        _tiles[index].Neighbors[0] = _tiles[index + 1];
            //    if (index != 0 && _tiles[index].file == _tiles[index - 1].file)
            //        _tiles[index].Neighbors[1] = _tiles[index - 1];

            //    // Construct the rest
            //    if (_tiles[index].file < (File)_dimension - 1)                     // 0 to _dimension - 1
            //    {
            //        _tiles[index].Neighbors[2] = _tiles[index + _dimension + 1 + (int)_tiles[index].file];
            //        _tiles[index].Neighbors[4] = _tiles[index + _dimension + (int)_tiles[index].file];
            //        if (_tiles[index].file != 0)
            //        {
            //            if (_tiles[index].file == _tiles[index + 1].file)
            //                _tiles[index].Neighbors[3] = _tiles[index - _dimension + 1 - (int)_tiles[index].file];
            //            if (_tiles[index].rank != 0)
            //                _tiles[index].Neighbors[5] = _tiles[index - _dimension - (int)_tiles[index].file];
            //        }
            //    }
            //    else if (_tiles[index].file == (File)_dimension - 1)               // Middle column
            //    {
            //        if (_tiles[index].rank != (Rank)((_dimension * 2) - 2))
            //        {
            //            _tiles[index].Neighbors[2] = _tiles[index + ((_dimension * 2) - 1)];
            //            _tiles[index].Neighbors[3] = _tiles[index - ((_dimension * 2) - 1) + 1];
            //        }
            //        if (_tiles[index].rank != 0)
            //        {
            //            _tiles[index].Neighbors[4] = _tiles[index + ((_dimension * 2) - 1) - 1];
            //            _tiles[index].Neighbors[5] = _tiles[index - ((_dimension * 2) - 1)];
            //        }
            //    }
            //    else                                                // _dimension to _dimension * 2 - 1
            //    {
            //        _tiles[index].Neighbors[3] = _tiles[index - ((_dimension * 2) - 1) + ((int)_tiles[index].file - _dimension) + 1];
            //        _tiles[index].Neighbors[5] = _tiles[index - ((_dimension * 2) - 1) + ((int)_tiles[index].file - _dimension)];
            //        if (_tiles[index].file != (File)((_dimension * 2) - 2))
            //        {
            //            if (_tiles[index].file == _tiles[index + 1].file)
            //                _tiles[index].Neighbors[2] = _tiles[index + ((_dimension * 2) - 1) - (int)_tiles[index].file + _dimension - 1];
            //            if (_tiles[index].rank != 0)
            //                _tiles[index].Neighbors[4] = _tiles[index + ((_dimension * 2) - 1) - (int)_tiles[index].file + _dimension - 2];
            //        }
            //    }
            //}
            // Tiles are constructed in increasing rank, then file, such as A1, A2, ... A6, B1, B2...
            int index = 0;
            tiles = new Tile[91];
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6 + i; j++)
                {
                    tiles[index] = new Tile(index, (File)i, (Rank)j);
                    index++;
                }
            }
            // Construct the last 5 files (G - L inclusive) with all their ranks (decreasing from 10 max)...
            for (int i = 6; i < 11; i++)
            {
                for (int j = 0; j < 11 + 5 - i; j++)
                {
                    tiles[index] = new Tile(index, (File)i, (Rank)j);
                    index++;
                }
            }

            // Construct the neighbors
            for (index = 0; index < tiles.Length; index++)
            {
                if (index != 90 && tiles[index].file == tiles[index + 1].file)
                    tiles[index].Neighbors[0] = tiles[index + 1];
                if (index != 0 && tiles[index].file == tiles[index - 1].file)
                    tiles[index].Neighbors[1] = tiles[index - 1];
                if (tiles[index].file < File.F)                     // ABCDE
                {
                    tiles[index].Neighbors[2] = tiles[index + 7 + (int)tiles[index].file];
                    tiles[index].Neighbors[4] = tiles[index + 6 + (int)tiles[index].file];
                    if (tiles[index].file != File.A)
                    {
                        if (tiles[index].file == tiles[index + 1].file)
                            tiles[index].Neighbors[3] = tiles[index - 5 - (int)tiles[index].file];
                        if (tiles[index].rank != Rank.One)
                            tiles[index].Neighbors[5] = tiles[index - 6 - (int)tiles[index].file];
                    }
                }
                else if (tiles[index].file == File.F)               // F
                {
                    if (tiles[index].rank != Rank.Eleven)
                    {
                        tiles[index].Neighbors[2] = tiles[index + 11];
                        tiles[index].Neighbors[3] = tiles[index - 10];
                    }
                    if (tiles[index].rank != Rank.One)
                    {
                        tiles[index].Neighbors[4] = tiles[index + 10];
                        tiles[index].Neighbors[5] = tiles[index - 11];
                    }
                }
                else                                                // GHIKL
                {
                    tiles[index].Neighbors[3] = tiles[index - 11 + ((int)tiles[index].file - (int)File.F)];
                    tiles[index].Neighbors[5] = tiles[index - 12 + ((int)tiles[index].file - (int)File.F)];
                    if (tiles[index].file != File.L)
                    {
                        if (tiles[index].file == tiles[index + 1].file)
                            tiles[index].Neighbors[2] = tiles[index + 11 + ((int)File.F - (int)tiles[index].file)];
                        if (tiles[index].rank != Rank.One)
                            tiles[index].Neighbors[4] = tiles[index + 10 + ((int)File.F - (int)tiles[index].file)];
                    }
                }
            }

            // Set the tile colors for display
            int tileStart = 0;
            int tileInner = tileStart;
            tiles[0].color = TileColor.Dark;
            for (index = 1; index < tiles.Length; index++)
            {
                if (tiles[index].file != tiles[index - 1].file)
                {
                    if (tiles[index].file < File.G)
                    {
                        tileStart++;
                        if (tileStart > 2)
                            tileStart = 0;
                    }
                    else
                    {
                        tileStart--;
                        if (tileStart < 0)
                            tileStart = 2;
                    }
                    tiles[index].color = (TileColor)tileStart;
                    tileInner = tileStart;
                }
                else
                {
                    tileInner++;
                    if (tileInner > 2)
                        tileInner = 0;
                    tiles[index].color = (TileColor)tileInner;
                }
            }
        }

        /// <summary>
        /// Create the tiles in the gameboard for the Shafran version, and assign neighbor values.
        /// ^     0
        /// | 3       2
        /// |     T
        /// | 5       4
        /// |     1
        /// ----------->
        /// </summary>
        /// <param name="tiles"></param>
        public static void ConstructTilesShafran(ref Tile[] tiles)
        {
            // Assign tiles to the array, File then Rank
            // We have 9 files and 10 ranks, starting with files first.
            // Construct the first 5 files (A - E inclusive) with all their ranks (increasing to 10 max)...
            // Tiles are constructed in increasing rank, then file, such as A1, A2, ... A6, B1, B2...
            int index = 0;
            tiles = new Tile[70];
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 6 + i; j++)
                {
                    tiles[index] = new Tile(index, (File)i, (Rank)j);
                    index++;
                }
            }
            // Construct the last 5 files (F - I inclusive) with all their ranks (decreasing from 9 max)...
            for (int i = 5; i < 9; i++)
            {
                for (int j = i - 4; j < 10; j++)
                {
                    tiles[index] = new Tile(index, (File)i, (Rank)j);
                    index++;
                }
            }

            // Construct the neighbors
            for (index = 0; index < 70; index++)
            {
                if (index != 69 && tiles[index].file == tiles[index + 1].file)
                    tiles[index].Neighbors[0] = tiles[index + 1];
                if (index != 0 && tiles[index].file == tiles[index - 1].file)
                    tiles[index].Neighbors[1] = tiles[index - 1];
                if (tiles[index].file < File.E)                     // ABCD
                {
                    tiles[index].Neighbors[2] = tiles[index + 7 + (int)tiles[index].file];
                    tiles[index].Neighbors[4] = tiles[index + 6 + (int)tiles[index].file];
                    if (tiles[index].file != File.A)
                    {
                        if (tiles[index].file == tiles[index + 1].file)
                            tiles[index].Neighbors[3] = tiles[index - 5 - (int)tiles[index].file];
                        if (tiles[index].rank != Rank.One)
                            tiles[index].Neighbors[5] = tiles[index - 6 - (int)tiles[index].file];
                    }
                }
                else if (tiles[index].file == File.E)               // E
                {
                    if (tiles[index].rank != Rank.Ten)
                    {
                        tiles[index].Neighbors[2] = tiles[index + 10];
                        tiles[index].Neighbors[3] = tiles[index - 9];
                    }
                    if (tiles[index].rank != Rank.One)
                    {
                        tiles[index].Neighbors[4] = tiles[index + 9];
                        tiles[index].Neighbors[5] = tiles[index - 10];
                    }
                }
                else                                                // FGHI
                {
                    tiles[index].Neighbors[3] = tiles[index - 10 + ((int)tiles[index].file - (int)File.E)];
                    tiles[index].Neighbors[5] = tiles[index - 11 + ((int)tiles[index].file - (int)File.E)];
                    if (tiles[index].file != File.I)
                    {
                        if (tiles[index].file == tiles[index + 1].file)
                            tiles[index].Neighbors[2] = tiles[index + 10 + ((int)File.E - (int)tiles[index].file)];
                        if (index != 40 && index != 49 && index != 57 && index != 64)
                            tiles[index].Neighbors[4] = tiles[index + 9 + ((int)File.E - (int)tiles[index].file)];
                    }
                }
            }


            // Set the tile colors for display
            int tileStart = 0;
            int tileInner = tileStart;
            tiles[0].color = TileColor.Dark;
            for (index = 1; index < 70; index++)
            {
                if (tiles[index].file != tiles[index - 1].file)
                {
                    if (tiles[index].file < File.F)
                    {
                        tileStart++;
                        if (tileStart > 2)
                            tileStart = 0;
                    }
                    else
                    {
                        tileStart--;
                        if (tileStart < 0)
                            tileStart = 2;
                    }
                    tiles[index].color = (TileColor)tileStart;
                    tileInner = tileStart;
                }
                else
                {
                    tileInner++;
                    if (tileInner > 2)
                        tileInner = 0;
                    tiles[index].color = (TileColor)tileInner;
                }
            }
        }

        public static void PlaceModelPositions(ref Tile[] tiles, GameVariant variant)
        {
            // Now, assign the models position in 3D space
            // Files move in increasing Z space, Ranks in increasing/decreasing X space.
            // Example: using tileDimZ: 46 and tileDimX: 78
            // X increases along the files from A to I/L
            // Z decreases along the ranks from 1 to 10/11
            // Example, {X, Z}: Glinsky/McCooey: A1{0, 0} A6{0, -230} F1{195, 115} F11{195, -345} L1{390, 0} L6{390, -230}
            // Shafran: A1{0, 0} A6{0, -230} E1{156, 92} E11{156, -322} I1{312, 0} I6{312, -230}
            float XPos = 0.0f;
            float ZPos = 0.0f;
            float tileDimZ = 46.0f;
            float tileDimX = 78.0f;
            int _dimension = 6;
            for (int i = 0; i < tiles.Length; i++)
            {
                // On a new file
                if (i != 0 && tiles[i].file != tiles[i - 1].file)
                {
                    XPos += tileDimX / 2;    // something to this effect, shift enough over to interlock

                    switch (variant)
                    {
                        case GameVariant.Glinsky:
                        case GameVariant.McCooey:
                            if (tiles[i].file < (File)_dimension)
                            {
                                ZPos = +(tileDimZ / 2) * (int)tiles[i].file;
                            }
                            else
                            {
                                ZPos = +((tileDimZ / 2) * ((int)(_dimension * 2) - 2 - (int)tiles[i].file));
                            }
                            break;
                        case GameVariant.Shafran:
                            if (tiles[i].file < File.F)
                            {
                                ZPos = +(tileDimZ / 2) * (int)tiles[i].file;
                            }
                            else
                            {
                                ZPos = +((tileDimZ / 2) * ((int)File.I - (int)tiles[i].file));
                            }
                            break;
                    }
                }

                tiles[i].Position = new Vector3(XPos, 0.0f, ZPos);
                ZPos -= tileDimZ;
            }
        }

        public static void PlaceGlinksi(ref Tile[] tiles)
        {
            //------------------------------------------------
            // WHITE PIECES
            //------------------------------------------------
            // Pawns
            tiles[6].Piece = PieceType.Pawn;
            tiles[6].Side = PieceColor.White;
            tiles[6].PieceWasPawnOnStartingTile = true;
            tiles[6].IsWhitePawnStartingTile = true;
            tiles[14].Piece = PieceType.Pawn;
            tiles[14].Side = PieceColor.White;
            tiles[14].PieceWasPawnOnStartingTile = true;
            tiles[14].IsWhitePawnStartingTile = true;
            tiles[23].Piece = PieceType.Pawn;
            tiles[23].Side = PieceColor.White;
            tiles[23].PieceWasPawnOnStartingTile = true;
            tiles[23].IsWhitePawnStartingTile = true;
            tiles[33].Piece = PieceType.Pawn;
            tiles[33].Side = PieceColor.White;
            tiles[33].PieceWasPawnOnStartingTile = true;
            tiles[33].IsWhitePawnStartingTile = true;
            tiles[44].Piece = PieceType.Pawn;
            tiles[44].Side = PieceColor.White;
            tiles[44].PieceWasPawnOnStartingTile = true;
            tiles[44].IsWhitePawnStartingTile = true;
            tiles[54].Piece = PieceType.Pawn;
            tiles[54].Side = PieceColor.White;
            tiles[54].PieceWasPawnOnStartingTile = true;
            tiles[54].IsWhitePawnStartingTile = true;
            tiles[63].Piece = PieceType.Pawn;
            tiles[63].Side = PieceColor.White;
            tiles[63].PieceWasPawnOnStartingTile = true;
            tiles[63].IsWhitePawnStartingTile = true;
            tiles[71].Piece = PieceType.Pawn;
            tiles[71].Side = PieceColor.White;
            tiles[71].PieceWasPawnOnStartingTile = true;
            tiles[71].IsWhitePawnStartingTile = true;
            tiles[78].Piece = PieceType.Pawn;
            tiles[78].Side = PieceColor.White;
            tiles[78].PieceWasPawnOnStartingTile = true;
            tiles[78].IsWhitePawnStartingTile = true;

            // Rooks
            tiles[13].Piece = PieceType.Rook;
            tiles[13].Side = PieceColor.White;
            tiles[70].Piece = PieceType.Rook;
            tiles[70].Side = PieceColor.White;

            // Knights
            tiles[21].Piece = PieceType.Knight;
            tiles[21].Side = PieceColor.White;
            tiles[61].Piece = PieceType.Knight;
            tiles[61].Side = PieceColor.White;

            // Bishops
            tiles[40].Piece = PieceType.Bishop;
            tiles[40].Side = PieceColor.White;
            tiles[41].Piece = PieceType.Bishop;
            tiles[41].Side = PieceColor.White;
            tiles[42].Piece = PieceType.Bishop;
            tiles[42].Side = PieceColor.White;

            // Queens
            tiles[30].Piece = PieceType.Queen;
            tiles[30].Side = PieceColor.White;

            // Kings
            tiles[51].Piece = PieceType.King;
            tiles[51].Side = PieceColor.White;

            //------------------------------------------------
            // BLACK PIECES
            //------------------------------------------------
            // Pawns
            tiles[12].Piece = PieceType.Pawn;
            tiles[12].Side = PieceColor.Black;
            tiles[12].PieceWasPawnOnStartingTile = true;
            tiles[12].IsBlackPawnStartingTile = true;
            tiles[19].Piece = PieceType.Pawn;
            tiles[19].Side = PieceColor.Black;
            tiles[19].PieceWasPawnOnStartingTile = true;
            tiles[19].IsBlackPawnStartingTile = true;
            tiles[27].Piece = PieceType.Pawn;
            tiles[27].Side = PieceColor.Black;
            tiles[27].PieceWasPawnOnStartingTile = true;
            tiles[27].IsBlackPawnStartingTile = true;
            tiles[36].Piece = PieceType.Pawn;
            tiles[36].Side = PieceColor.Black;
            tiles[36].PieceWasPawnOnStartingTile = true;
            tiles[36].IsBlackPawnStartingTile = true;
            tiles[46].Piece = PieceType.Pawn;
            tiles[46].Side = PieceColor.Black;
            tiles[46].PieceWasPawnOnStartingTile = true;
            tiles[46].IsBlackPawnStartingTile = true;
            tiles[57].Piece = PieceType.Pawn;
            tiles[57].Side = PieceColor.Black;
            tiles[57].PieceWasPawnOnStartingTile = true;
            tiles[57].IsBlackPawnStartingTile = true;
            tiles[67].Piece = PieceType.Pawn;
            tiles[67].Side = PieceColor.Black;
            tiles[67].PieceWasPawnOnStartingTile = true;
            tiles[67].IsBlackPawnStartingTile = true;
            tiles[76].Piece = PieceType.Pawn;
            tiles[76].Side = PieceColor.Black;
            tiles[76].PieceWasPawnOnStartingTile = true;
            tiles[76].IsBlackPawnStartingTile = true;
            tiles[84].Piece = PieceType.Pawn;
            tiles[84].Side = PieceColor.Black;
            tiles[84].PieceWasPawnOnStartingTile = true;
            tiles[84].IsBlackPawnStartingTile = true;

            // Rooks
            tiles[20].Piece = PieceType.Rook;
            tiles[20].Side = PieceColor.Black;
            tiles[77].Piece = PieceType.Rook;
            tiles[77].Side = PieceColor.Black;

            // Knights
            tiles[69].Piece = PieceType.Knight;
            tiles[69].Side = PieceColor.Black;
            tiles[29].Piece = PieceType.Knight;
            tiles[29].Side = PieceColor.Black;

            // Bishops
            tiles[50].Piece = PieceType.Bishop;
            tiles[50].Side = PieceColor.Black;
            tiles[49].Piece = PieceType.Bishop;
            tiles[49].Side = PieceColor.Black;
            tiles[48].Piece = PieceType.Bishop;
            tiles[48].Side = PieceColor.Black;

            // Queens
            tiles[39].Piece = PieceType.Queen;
            tiles[39].Side = PieceColor.Black;

            // Kings
            tiles[60].Piece = PieceType.King;
            tiles[60].Side = PieceColor.Black;
        }

        public static void PlaceMcCooey(ref Tile[] tiles)
        {
            //------------------------------------------------
            // WHITE PIECES
            //------------------------------------------------
            // Pawns
            tiles[13].Piece = PieceType.Pawn;
            tiles[13].Side = PieceColor.White;
            tiles[13].PieceWasPawnOnStartingTile = true;
            tiles[13].IsWhitePawnStartingTile = true;
            tiles[22].Piece = PieceType.Pawn;
            tiles[22].Side = PieceColor.White;
            tiles[22].PieceWasPawnOnStartingTile = true;
            tiles[22].IsWhitePawnStartingTile = true;
            tiles[32].Piece = PieceType.Pawn;
            tiles[32].Side = PieceColor.White;
            tiles[32].PieceWasPawnOnStartingTile = true;
            tiles[32].IsWhitePawnStartingTile = true;
            tiles[43].Piece = PieceType.Pawn;
            tiles[43].Side = PieceColor.White;
            tiles[43].PieceWasPawnOnStartingTile = true;
            tiles[43].IsWhitePawnStartingTile = true;
            tiles[53].Piece = PieceType.Pawn;
            tiles[53].Side = PieceColor.White;
            tiles[53].PieceWasPawnOnStartingTile = true;
            tiles[53].IsWhitePawnStartingTile = true;
            tiles[62].Piece = PieceType.Pawn;
            tiles[62].Side = PieceColor.White;
            tiles[62].PieceWasPawnOnStartingTile = true;
            tiles[62].IsWhitePawnStartingTile = true;
            tiles[70].Piece = PieceType.Pawn;
            tiles[70].Side = PieceColor.White;
            tiles[70].PieceWasPawnOnStartingTile = true;
            tiles[70].IsWhitePawnStartingTile = true;

            // Rooks
            tiles[21].Piece = PieceType.Rook;
            tiles[21].Side = PieceColor.White;
            tiles[61].Piece = PieceType.Rook;
            tiles[61].Side = PieceColor.White;

            // Knights
            tiles[31].Piece = PieceType.Knight;
            tiles[31].Side = PieceColor.White;
            tiles[52].Piece = PieceType.Knight;
            tiles[52].Side = PieceColor.White;

            // Bishops
            tiles[40].Piece = PieceType.Bishop;
            tiles[40].Side = PieceColor.White;
            tiles[41].Piece = PieceType.Bishop;
            tiles[41].Side = PieceColor.White;
            tiles[42].Piece = PieceType.Bishop;
            tiles[42].Side = PieceColor.White;

            // Queens
            tiles[30].Piece = PieceType.Queen;
            tiles[30].Side = PieceColor.White;

            // Kings
            tiles[51].Piece = PieceType.King;
            tiles[51].Side = PieceColor.White;

            //------------------------------------------------
            // BLACK PIECES
            //------------------------------------------------
            // Pawns
            tiles[20].Piece = PieceType.Pawn;
            tiles[20].Side = PieceColor.Black;
            tiles[20].PieceWasPawnOnStartingTile = true;
            tiles[20].IsBlackPawnStartingTile = true;
            tiles[28].Piece = PieceType.Pawn;
            tiles[28].Side = PieceColor.Black;
            tiles[28].PieceWasPawnOnStartingTile = true;
            tiles[28].IsBlackPawnStartingTile = true;
            tiles[37].Piece = PieceType.Pawn;
            tiles[37].Side = PieceColor.Black;
            tiles[37].PieceWasPawnOnStartingTile = true;
            tiles[37].IsBlackPawnStartingTile = true;
            tiles[47].Piece = PieceType.Pawn;
            tiles[47].Side = PieceColor.Black;
            tiles[47].PieceWasPawnOnStartingTile = true;
            tiles[47].IsBlackPawnStartingTile = true;
            tiles[58].Piece = PieceType.Pawn;
            tiles[58].Side = PieceColor.Black;
            tiles[58].PieceWasPawnOnStartingTile = true;
            tiles[58].IsBlackPawnStartingTile = true;
            tiles[68].Piece = PieceType.Pawn;
            tiles[68].Side = PieceColor.Black;
            tiles[68].PieceWasPawnOnStartingTile = true;
            tiles[68].IsBlackPawnStartingTile = true;
            tiles[77].Piece = PieceType.Pawn;
            tiles[77].Side = PieceColor.Black;
            tiles[77].PieceWasPawnOnStartingTile = true;
            tiles[77].IsBlackPawnStartingTile = true;

            // Rooks
            tiles[29].Piece = PieceType.Rook;
            tiles[29].Side = PieceColor.Black;
            tiles[69].Piece = PieceType.Rook;
            tiles[69].Side = PieceColor.Black;

            // Knights
            tiles[38].Piece = PieceType.Knight;
            tiles[38].Side = PieceColor.Black;
            tiles[59].Piece = PieceType.Knight;
            tiles[59].Side = PieceColor.Black;

            // Bishops
            tiles[50].Piece = PieceType.Bishop;
            tiles[50].Side = PieceColor.Black;
            tiles[49].Piece = PieceType.Bishop;
            tiles[49].Side = PieceColor.Black;
            tiles[48].Piece = PieceType.Bishop;
            tiles[48].Side = PieceColor.Black;

            // Queens
            tiles[39].Piece = PieceType.Queen;
            tiles[39].Side = PieceColor.Black;

            // Kings
            tiles[60].Piece = PieceType.King;
            tiles[60].Side = PieceColor.Black;
        }

        public static void PlaceShafran(ref Tile[] tiles)
        {
            //------------------------------------------------
            // WHITE PIECES
            //------------------------------------------------
            // Pawns
            tiles[1].Piece = PieceType.Pawn;
            tiles[1].Side = PieceColor.White;
            tiles[1].PieceWasPawnOnStartingTile = true;
            tiles[1].IsWhitePawnStartingTile = true;
            tiles[7].Piece = PieceType.Pawn;
            tiles[7].Side = PieceColor.White;
            tiles[7].PieceWasPawnOnStartingTile = true;
            tiles[7].IsWhitePawnStartingTile = true;
            tiles[14].Piece = PieceType.Pawn;
            tiles[14].Side = PieceColor.White;
            tiles[14].PieceWasPawnOnStartingTile = true;
            tiles[14].IsWhitePawnStartingTile = true;
            tiles[22].Piece = PieceType.Pawn;
            tiles[22].Side = PieceColor.White;
            tiles[22].PieceWasPawnOnStartingTile = true;
            tiles[22].IsWhitePawnStartingTile = true;
            tiles[31].Piece = PieceType.Pawn;
            tiles[31].Side = PieceColor.White;
            tiles[31].PieceWasPawnOnStartingTile = true;
            tiles[31].IsWhitePawnStartingTile = true;
            tiles[41].Piece = PieceType.Pawn;
            tiles[41].Side = PieceColor.White;
            tiles[41].PieceWasPawnOnStartingTile = true;
            tiles[41].IsWhitePawnStartingTile = true;
            tiles[50].Piece = PieceType.Pawn;
            tiles[50].Side = PieceColor.White;
            tiles[50].PieceWasPawnOnStartingTile = true;
            tiles[50].IsWhitePawnStartingTile = true;
            tiles[58].Piece = PieceType.Pawn;
            tiles[58].Side = PieceColor.White;
            tiles[58].PieceWasPawnOnStartingTile = true;
            tiles[58].IsWhitePawnStartingTile = true;
            tiles[65].Piece = PieceType.Pawn;
            tiles[65].Side = PieceColor.White;
            tiles[65].PieceWasPawnOnStartingTile = true;
            tiles[65].IsWhitePawnStartingTile = true;

            // Rooks
            tiles[0].Piece = PieceType.Rook;
            tiles[0].Side = PieceColor.White;
            tiles[64].Piece = PieceType.Rook;
            tiles[64].Side = PieceColor.White;

            // Knights
            tiles[6].Piece = PieceType.Knight;
            tiles[6].Side = PieceColor.White;
            tiles[49].Piece = PieceType.Knight;
            tiles[49].Side = PieceColor.White;

            // Bishops
            tiles[13].Piece = PieceType.Bishop;
            tiles[13].Side = PieceColor.White;
            tiles[40].Piece = PieceType.Bishop;
            tiles[40].Side = PieceColor.White;
            tiles[57].Piece = PieceType.Bishop;
            tiles[57].Side = PieceColor.White;

            // Queens
            tiles[21].Piece = PieceType.Queen;
            tiles[21].Side = PieceColor.White;

            // Kings
            tiles[30].Piece = PieceType.King;
            tiles[30].Side = PieceColor.White;

            //------------------------------------------------
            // BLACK PIECES
            //------------------------------------------------
            // Pawns
            tiles[4].Piece = PieceType.Pawn;
            tiles[4].Side = PieceColor.Black;
            tiles[4].PieceWasPawnOnStartingTile = true;
            tiles[4].IsBlackPawnStartingTile = true;
            tiles[11].Piece = PieceType.Pawn;
            tiles[11].Side = PieceColor.Black;
            tiles[11].PieceWasPawnOnStartingTile = true;
            tiles[11].IsBlackPawnStartingTile = true;
            tiles[19].Piece = PieceType.Pawn;
            tiles[19].Side = PieceColor.Black;
            tiles[19].PieceWasPawnOnStartingTile = true;
            tiles[19].IsBlackPawnStartingTile = true;
            tiles[28].Piece = PieceType.Pawn;
            tiles[28].Side = PieceColor.Black;
            tiles[28].PieceWasPawnOnStartingTile = true;
            tiles[28].IsBlackPawnStartingTile = true;
            tiles[38].Piece = PieceType.Pawn;
            tiles[38].Side = PieceColor.Black;
            tiles[38].PieceWasPawnOnStartingTile = true;
            tiles[38].IsBlackPawnStartingTile = true;
            tiles[47].Piece = PieceType.Pawn;
            tiles[47].Side = PieceColor.Black;
            tiles[47].PieceWasPawnOnStartingTile = true;
            tiles[47].IsBlackPawnStartingTile = true;
            tiles[55].Piece = PieceType.Pawn;
            tiles[55].Side = PieceColor.Black;
            tiles[55].PieceWasPawnOnStartingTile = true;
            tiles[55].IsBlackPawnStartingTile = true;
            tiles[62].Piece = PieceType.Pawn;
            tiles[62].Side = PieceColor.Black;
            tiles[62].PieceWasPawnOnStartingTile = true;
            tiles[62].IsBlackPawnStartingTile = true;
            tiles[68].Piece = PieceType.Pawn;
            tiles[68].Side = PieceColor.Black;
            tiles[68].PieceWasPawnOnStartingTile = true;
            tiles[68].IsBlackPawnStartingTile = true;

            // Rooks
            tiles[5].Piece = PieceType.Rook;
            tiles[5].Side = PieceColor.Black;
            tiles[69].Piece = PieceType.Rook;
            tiles[69].Side = PieceColor.Black;

            // Knights
            tiles[20].Piece = PieceType.Knight;
            tiles[20].Side = PieceColor.Black;
            tiles[63].Piece = PieceType.Knight;
            tiles[63].Side = PieceColor.Black;

            // Bishops
            tiles[12].Piece = PieceType.Bishop;
            tiles[12].Side = PieceColor.Black;
            tiles[29].Piece = PieceType.Bishop;
            tiles[29].Side = PieceColor.Black;
            tiles[56].Piece = PieceType.Bishop;
            tiles[56].Side = PieceColor.Black;

            // Queens
            tiles[48].Piece = PieceType.Queen;
            tiles[48].Side = PieceColor.Black;

            // Kings
            tiles[39].Piece = PieceType.King;
            tiles[39].Side = PieceColor.Black;
        }
    }
}